package cn.tedu.icop.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class RedisConfig  {
        @Bean
        public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory)
        {
            RedisTemplate redisTemplate = new RedisTemplate();
            //设置连接工厂
            redisTemplate.setConnectionFactory(connectionFactory);
            //设置key序列化器
            redisTemplate.setKeySerializer(RedisSerializer.string());
            //设置value序列化器
            redisTemplate.setValueSerializer(RedisSerializer.json());
            //设置Hash value序列化器
            redisTemplate.setHashValueSerializer(RedisSerializer.json());
            //设置Hash key序列化器
            redisTemplate.setHashKeySerializer(RedisSerializer.string());
            return redisTemplate;
        }



}
